import { Column, Entity, PrimaryGeneratedColumn, Unique, OneToMany,  } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";

@Entity("users")

@ManualTimestamp()
export class UserEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column({ type: "varchar", length: 32 })
  mobile!: string;

  // 存储前端传递的 MD5 密码（32位）
  @Column({ type: "varchar", length: 64 })
  passwordHash!: string;

  // 移除accessToken和tokenIssuedAt字段，因为token不再存储在数据库中
  // 这些信息将存储在Redis缓存中

  @Column({ type: "varchar", length: 64, nullable: true })
  channel!: string | null;

  @Column({ type: "varchar", length: 64, nullable: true })
  inviteCode!: string | null;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", {
    name: "updated_at",
    comment: "更新时间",
    nullable: true,
  })
  updated_at!: Date | null;

  @OneToMany(() => CharacterEntity, (character) => character.user)
  characters?: CharacterEntity[];
}
